/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controlers;

import gestionnaires.GestionFilm;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 *
 * @author mazid
 */
@WebListener
public class InitDataBase implements ServletContextListener{
    GestionFilm gestionFilm = lookupGestionFilmBean();
    

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        gestionFilm.creerFilmsTest();
    }
    
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        
    }

    private GestionFilm lookupGestionFilmBean() {
        try {
            Context c = new InitialContext();
            return (GestionFilm) c.lookup("java:global/Projet-Web/GestionFilm!gestionnaires.GestionFilm");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
    
}
